{% extends 'store/base.html' %}
{% block style %}
    <style>
        li{
            list-style: none;
            margin-top: 30px;
        }
    </style>

{% endblock %}
{% block content %}
    <!--面板部分-->
    <div class="container-fluid">
        <div class="card shadow mb-4">
            <div class="card-header py-3">
              <h4 class="m-0 font-weight-bold text-primary">注册店铺想·</h4>
            </div>
            <div class="card-body">
                <ul>

                    <li rowspan="4">
                        <label class="t_label">店铺名称</label>
                        <input id="store_name" class="form-control" type="text" placeholder="店铺名称">
                    </li>
                    <li rowspan="4">
                        <label class="t_label">店铺地址</label>
                        <input id="store_address" class="form-control" type="text" placeholder="店铺地址">
                    </li>
                    <li rowspan="4">
                        <label class="t_label">店铺描述</label>
                        <textarea id="store_description"  class="form-control"></textarea>
                    </li>
                    <li rowspan="4">
                        <label class="t_label">店铺logo</label>
                        <input id="store_picture" class="form-control" type="file" >
                    </li>
                    <li rowspan="4">
                        <input class="btn btn-primary" onclick="submit()" type="button" value="注册店铺">
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <script>
        function submit() {
            var store_name = document.getElementById("store_name").value;
            var store_address = document.getElementById("store_address").value;
            var store_description = document.getElementById("store_description").value;
            var store_picture = document.getElementById("store_picture").files[0];

            var formdata = new FormData();
            formdata.append('store_name',store_name);
            formdata.append('store_address',store_address);
            formdata.append('store_description',store_description);
            formdata.append('store_picture',store_picture);
            formdata.append('csrfmiddlewaretoken','{{ csrf_token }}');

            $.ajax({
                url: "/Store/add_store_ajax/",
                type: "post",
                data: formdata,
                processData: false,
                contentType: false,
                success:function (res) {
                    if(res.code === 200){
                        window.location.href = "/Store/store/"
                    }
                },
                error: function (error) {
                    console.log(error)
                }
            })

        }
    </script>
{% endblock %}